package com.iwjw.ibatis.generate.util;

import com.iwjw.ibatis.generate.model.GenerateConfig;
import com.iwjw.ibatis.mapper.ISqlInjector;


/**
 * @author: huangweiwei
 * @email: ihuangweiwei@163.com
 * @created:2016/10/25
 */
public class BuildXmlUtil {

    private static final String XML_TEMPLATE = "" +
            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
            "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >\n" +
            "<mapper namespace=\"%s\" >\n" +
            "    <!--请勿设置，只是用于XML编译的问题-->\n" +
            "    <resultMap id=\"" + ISqlInjector.DEFAULT_RESULT_MAP + "\" type=\"%s\"/>\n" +
            "\n" +
            "</mapper>";


    public static boolean build(String path, String mapperPkg, String modelPkg, String model) {
        String xml = String.format(XML_TEMPLATE, mapperPkg + "." + model + "Mapper", modelPkg + "." + model).trim();
        return FileUtil.writeXml(GenerateConfig.XML_PATH, model + "Mapper.xml", xml, GenerateConfig.OVERRIDE_FILE);
    }


}
